﻿IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[esf_files].[P_InsertFileReference]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [esf_files].[P_InsertFileReference]
GO


CREATE PROCEDURE esf_files.P_InsertFileReference
	@pDescription varchar(260)
    ,@pURL varchar(3000)
    ,@pLengthBytes bigint
    ,@pFileTypeID int
    ,@pCreationDateTime datetime
    ,@pLastUpdateDateTime datetime
	,@pLastUpdateAction datetime
    ,@pLastWriteDateTime datetime
    ,@pMonitoredDirectoryID int
    ,@pMonitoredDirectorySubCategoryID int
	,@pEnterpriseID int
    ,@pImageFormat varchar(10)
    ,@pOnlyName varchar(100)
    ,@pOnlyExtension varchar(100)
    ,@pItemsCount int
    ,@pIsEnabled bit
    ,@pIsEnabledUserAlias varchar(20)
    ,@pIsEnabledDateTime datetime
    ,@pDownloadCount int
    ,@pLastDownloadUserAlias varchar(20)
    ,@pLastDownloadDateTime datetime
    ,@pOpenCount int
    ,@pLastOpenUserAlias varchar(20)
    ,@pLastOpenDateTime datetime
    ,@pLastMoveToSubCategoryUserAlias varchar(20)
    ,@pLastMoveToSubCategoryDateTime datetime
	,@pReadProcessingTimeMs INT
	,@pURLMD5 VARCHAR (100)
	,@pVersionDateTime DATETIME = NULL

	,@pID INT OUT

AS
	INSERT INTO [esf_files].[FileReference]
           ([Description]
           ,[URL]
           ,[LengthBytes]
           ,[FileTypeID]
           ,[CreationDateTime]
           ,[LastUpdateDateTime]
		   ,LastUpdateAction
           ,[LastWriteDateTime]
           ,[MonitoredDirectoryID]
           ,[MonitoredDirectorySubCategoryID]
		   ,EnterpriseID
           ,[ImageFormat]
           ,[OnlyName]
           ,[OnlyExtension]
           ,[ItemsCount]
           ,[IsEnabled]
           ,[IsEnabledUserAlias]
           ,[IsEnabledDateTime]
           ,[DownloadCount]
           ,[LastDownloadUserAlias]
           ,[LastDownloadDateTime]
           ,[OpenCount]
           ,[LastOpenUserAlias]
           ,[LastOpenDateTime]
           ,[LastMoveToSubCategoryUserAlias]
           ,[LastMoveToSubCategoryDateTime]
		   ,ReadProcessingTimeMs
		   ,URLMD5
		   ,VersionDateTime
		  )
     VALUES
           (@pDescription
           ,@pURL
           ,@pLengthBytes
           ,@pFileTypeID
           ,@pCreationDateTime
           ,@pLastUpdateDateTime
		   ,@pLastUpdateAction
           ,@pLastWriteDateTime
           ,@pMonitoredDirectoryID
           ,@pMonitoredDirectorySubCategoryID
		   ,@pEnterpriseID
           ,@pImageFormat
           ,@pOnlyName
           ,@pOnlyExtension
           ,@pItemsCount
           ,@pIsEnabled
           ,@pIsEnabledUserAlias
           ,@pIsEnabledDateTime
           ,@pDownloadCount
           ,@pLastDownloadUserAlias
           ,@pLastDownloadDateTime
           ,@pOpenCount
           ,@pLastOpenUserAlias
           ,@pLastOpenDateTime
           ,@pLastMoveToSubCategoryUserAlias
           ,@pLastMoveToSubCategoryDateTime
		   ,@pReadProcessingTimeMs
		   ,@pURLMD5
		   ,@pVersionDateTime)

	SET @pID = @@IDENTITY
GO

